package com.vayne.demo;

import com.vayne.bean.Person;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * 注解方式加载 Bean
 * @author xuerui.zhang
 * @since 2020/1/19 上午10:43
 */
public class AnnotationInjectionDemo {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(AnnotationInjectionDemo.class);
        // 启动应用上下文
        applicationContext.refresh();
        Person bean = applicationContext.getBean(Person.class);
        System.out.println(bean);
    }

    /**
     * 通过 Java 注解定义了一个 Bean
     */
    @Bean
    public Person person() {
        Person person = new Person();
        person.setName("Hello Java");
        person.setAge(10);
        return person;
    }
}
